<template>
	<view class='demand' v-if="status==0">
		<u-form :model="form" class="form_style">
			<u-form-item label="姓名">{{form.name}}</u-form-item>
			<u-form-item label="学号">{{form.studentId}}</u-form-item>
			<u-form-item label="专业">{{form.specialtyName}}</u-form-item>
			<u-form-item label="班级">{{form.className}}</u-form-item>
			<u-form-item label-width="120" label="宿舍楼号">
				<u-input v-model="form.dormitoryName" type="select" :border="true" @click="dormitoryNameListshow = true"/>
			</u-form-item>
			<u-form-item label-width="120" label="宿舍号">
				<u-input v-model="form.dormitoryId" type="select" :border="true" @click="dormitoryNameListshow = true"/>
			</u-form-item>
			<u-form-item label-width="120" label="床号">
				<u-input v-model="form.bedId" type="select" :border="true" @click="dormitoryNameListshow = true"/>
			</u-form-item>
		</u-form>
		<u-button :ripple="true" type="primary" @click="insertDormitory()">确认申请</u-button>
		<u-select v-model="dormitoryNameListshow" mode="mutil-column" :list="dormitoryNameList" @confirm="confirm"></u-select>
	</view>
	<view class="" v-else>
		<span><h5>您已申请过宿舍，请进入-我的宿舍-查询申请进度或查看宿舍信息</h5></span>
	</view>
</template>

<script>
	export default{
		name:'shenqing',
		data(){
			return{
				form:{
					"bedId": "",//床号
					"className": "",//班级
					"dormitoryId": "",//宿舍号
					"dormitoryName": "",//宿舍楼
					"name": "",//姓名
					"specialtyName": "",//专业
					"studentId": "",//学号
					"payInfo": "1"
				},
				dormitoryNameList:[
					[
						{value:7,label:'西一'},
						{value:8,label:'西二'},
						{value:9,label:'西三'},
						{value:10,label:'西四'},
						{value:11,label:'西五'},
						{value:12,label:'西六'},
						{value:13,label:'西七'},
						{value:14,label:'西八'},
						{value:15,label:'西九'},
						{value:16,label:'西十'},
						{value:17,label:'西十一'},
						{value:18,label:'西十二'},
						{value:19,label:'西十三'},
						{value:20,label:'西十四'},
						{value:21,label:'东一'},
						{value:22,label:'东二'},
						{value:23,label:'东三'},
						{value:24,label:'东四'},
						{value:25,label:'东五'},
						{value:26,label:'东六'},
						{value:27,label:'东七'},
						{value:28,label:'东八'},
						{value:29,label:'东九'},
						{value:30,label:'东十'},
						{value:31,label:'东十一'},
						{value:32,label:'东十二'},
						{value:33,label:'东十三'},
					],
					[
						{value:	34	,label:"101"},
						{value:	35	,label:"102"},
						{value:	36	,label:"103"},
						{value:	37	,label:"104"},
						{value:	38	,label:"105"},
						{value:	39	,label:"106"},
						{value:	40	,label:"107"},
						{value:	41	,label:"108"},
						{value:	42	,label:"109"},
						{value:	43	,label:"110"},
						{value:	44	,label:"111"},
						{value:	45	,label:"112"},
						{value:	46	,label:"113"},
						{value:	47	,label:"114"},
						{value:	48	,label:"115"},
						{value:	49	,label:"116"},
						{value:	50	,label:"117"},
						{value:	51	,label:"118"},
						{value:	52	,label:"119"},
						{value:	53	,label:"120"},
						{value:	54	,label:"121"},
						{value:	55	,label:"122"},
						{value:	56	,label:"123"},
						{value:	57	,label:"124"},
						{value:	58	,label:"125"},
						{value:	59	,label:"126"},
						{value:	60	,label:"127"},
						{value:	61	,label:"128"},
						{value:	62	,label:"129"},
						{value:	63	,label:"130"},
						{value:	64	,label:"131"},
						{value:	65	,label:"132"},
						{value:	66	,label:"201"},
						{value:	67	,label:"202"},
						{value:	68	,label:"203"},
						{value:	69	,label:"204"},
						{value:	70	,label:"205"},
						{value:	71	,label:"206"},
						{value:	72	,label:"207"},
						{value:	73	,label:"208"},
						{value:	74	,label:"209"},
						{value:	75	,label:"210"},
						{value:	76	,label:"211"},
						{value:	77	,label:"212"},
						{value:	78	,label:"213"},
						{value:	79	,label:"214"},
						{value:	80	,label:"215"},
						{value:	81	,label:"216"},
						{value:	82	,label:"217"},
						{value:	83	,label:"218"},
						{value:	84	,label:"219"},
						{value:	85	,label:"220"},
						{value:	86	,label:"221"},
						{value:	87	,label:"222"},
						{value:	88	,label:"223"},
						{value:	89	,label:"224"},
						{value:	90	,label:"225"},
						{value:	91	,label:"226"},
						{value:	92	,label:"227"},
						{value:	93	,label:"228"},
						{value:	94	,label:"229"},
						{value:	95	,label:"230"},
						{value:	96	,label:"231"},
						{value:	97	,label:"232"},
						{value:	98	,label:"301"},
						{value:	99	,label:"302"},
						{value:	100	,label:"303"},
						{value:	101	,label:"304"},
						{value:	102	,label:"305"},
						{value:	103	,label:"306"},
						{value:	104	,label:"307"},
						{value:	105	,label:"308"},
						{value:	106	,label:"309"},
						{value:	107	,label:"310"},
						{value:	108	,label:"311"},
						{value:	109	,label:"312"},
						{value:	110	,label:"313"},
						{value:	111	,label:"314"},
						{value:	112	,label:"315"},
						{value:	113	,label:"316"},
						{value:	114	,label:"317"},
						{value:	115	,label:"318"},
						{value:	116	,label:"319"},
						{value:	117	,label:"320"},
						{value:	118	,label:"321"},
						{value:	119	,label:"322"},
						{value:	120	,label:"323"},
						{value:	121	,label:"324"},
						{value:	122	,label:"325"},
						{value:	123	,label:"326"},
						{value:	124	,label:"327"},
						{value:	125	,label:"328"},
						{value:	126	,label:"329"},
						{value:	127	,label:"330"},
						{value:	128	,label:"331"},
						{value:	129	,label:"332"},
						{value:	130	,label:"401"},
						{value:	131	,label:"402"},
						{value:	132	,label:"403"},
						{value:	133	,label:"404"},
						{value:	134	,label:"405"},
						{value:	135	,label:"406"},
						{value:	136	,label:"407"},
						{value:	137	,label:"408"},
						{value:	138	,label:"409"},
						{value:	139	,label:"410"},
						{value:	140	,label:"411"},
						{value:	141	,label:"412"},
						{value:	142	,label:"413"},
						{value:	143	,label:"414"},
						{value:	144	,label:"415"},
						{value:	145	,label:"416"},
						{value:	146	,label:"417"},
						{value:	147	,label:"418"},
						{value:	148	,label:"419"},
						{value:	149	,label:"420"},
						{value:	150	,label:"421"},
						{value:	151	,label:"422"},
						{value:	152	,label:"423"},
						{value:	153	,label:"424"},
						{value:	154	,label:"425"},
						{value:	155	,label:"426"},
						{value:	156	,label:"427"},
						{value:	157	,label:"428"},
						{value:	158	,label:"429"},
						{value:	159	,label:"430"},
						{value:	160	,label:"431"},
						{value:	161	,label:"432"},
						{value:	162	,label:"501"},
						{value:	163	,label:"502"},
						{value:	164	,label:"503"},
						{value:	165	,label:"504"},
						{value:	166	,label:"505"},
						{value:	167	,label:"506"},
						{value:	168	,label:"507"},
						{value:	169	,label:"508"},
						{value:	170	,label:"509"},
						{value:	171	,label:"510"},
						{value:	172	,label:"511"},
						{value:	173	,label:"512"},
						{value:	174	,label:"513"},
						{value:	175	,label:"514"},
						{value:	176	,label:"515"},
						{value:	177	,label:"516"},
						{value:	178	,label:"517"},
						{value:	179	,label:"518"},
						{value:	180	,label:"519"},
						{value:	181	,label:"520"},
						{value:	182	,label:"521"},
						{value:	183	,label:"522"},
						{value:	184	,label:"523"},
						{value:	185	,label:"524"},
						{value:	186	,label:"525"},
						{value:	187	,label:"526"},
						{value:	188	,label:"527"},
						{value:	189	,label:"528"},
						{value:	190	,label:"529"},
						{value:	191	,label:"530"},
						{value:	192	,label:"531"},
						{value:	193	,label:"532"},
					],
					[
					  {value:1,label:'1床'},
					  {value:2,label:'2床'},
					  {value:3,label:'3床'},
					  {value:4,label:'4床'},
					  {value:5,label:'5床'},
					  {value:6,label:'6床'},
					]
				],
				dormitoryNameListshow:false,
				status:''
			}
		},
		onLoad() {
			this.getshenqingdata()
			this.getinfo()
		},
		methods:{
			confirm(e) {
				// console.log(e);
				this.form.dormitoryName=e[0].label
				this.form.dormitoryId=e[1].label
				this.form.bedId=e[2].label
			},
			dormitoryNameListCallback(index) {
				this.form.dormitoryName = this.dormitoryNameList[index].text;
			},
			getinfo(){
				var value=uni.getStorageSync('myinfo')
				console.log(value)
				this.form.name=value.matriculate.name
				this.form.studentId=value.matriculate.studentId
				this.form.specialtyName=value.matriculate.specialtyName
				this.form.className=value.matriculate.className
			},
			insertDormitory(){
				var len=this.form.studentId.length;
				var na=this.form.name;
				if(len!=10 || na==''){
					uni.showToast({
						title:'请输入正确的信息',
						icon:"none",
						duration: 1000
					});
					return
				}
				uni.request({
					url:'http://taruinfo.work:8088/dormitory/updateUserInfo',
					data:this.form,
					method:'POST',
					success:function(res){
						console.log(res.data.code)
						if(res.data.code ==200){
							uni.showToast({
							    title: res.data.message,
								icon:"success",
							    duration: 2000
							});
							setTimeout(function() {
								uni.redirectTo({
									url:'../index/index'
								})
							},1500);
						}else{
							console.log(res.data.message)
							uni.showToast({
									title:res.data.message,
									icon:"none",
									duration: 2000
							});
						}
					},
					fail:function(res){
						uni.showToast({
						    title:'出错了，请联系开发者',
							icon:"none",
						    duration: 2000
						});
					}
				})
			},
		getshenqingdata(){
			var _this=this
			let value=uni.getStorageSync('myinfo')
			let studentId=value.user.studentId
			var url='http://taruinfo.work:8088/getDormitoryByLists?current=1&size=10&studentId='+studentId;
			uni.request({
				url:url,
				method:'get',
				success:function(res){
					_this.status=res.data.data.records[0].payInfo
				},
				fail:function(res){
					uni.showToast({
						title:res.data.message,
						icon:'none'
					})
				}
			})
		}
		}
	}
</script>

<style scoped lang="less">
	.demand{
		margin-left: 20rpx;
		margin-right: 20rpx;
	}
</style>
